/**
 * 生成uuid
 * @returns {string}
 */
export function guid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    let r = Math.random() * 16 | 0,
      v = c === 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

/**
 * 深拷贝对象
 * @param obj
 * @param newObj
 * @returns 新对象
 */
export function deepClone(obj, newObj) {
  newObj = newObj || {}
  for (let key in obj) {
    if (typeof obj[key] == 'object') {
      newObj[key] = obj[key].constructor === Array ? [] : {}
      deepClone(obj[key], newObj[key])
    } else {
      newObj[key] = obj[key]
    }
  }
  return newObj
}

export function reMatch(reg_g, str) {
  // let reg_g = reg_g;
  let result = null;
  let list = [];
  do {
    result = reg_g.exec(str);
    result && list.push(result[1]);
  } while (result)
  console.log("reList=", list);
  return list;
}

export function recursion(list, arr) {
  arr && arr.map(item => {
    if (item.children != null && item.children.length > 0) {
      return recursion(item.children)
    } else {
      list.push(item)
    }
  })
}

export function removeDuplicateObj(arr) {
  let obj = {};
  arr = arr.reduce((newArr, next) => {
    (obj[next.id] && obj[next.optData]) ? "" : (obj[next.id] = true && newArr.push(next));
    return newArr;
  }, []);
  return arr;
}
